<script setup lang="ts">
import JsBarcode from 'jsbarcode'
import { ContentDetailWrap } from '@/components/ContentDetailWrap'
import { ref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { useRouter, useRoute } from 'vue-router'
import { getSnDetailApi } from '@/api/snManage'

const { push, go } = useRouter()

const { query } = useRoute()

const { t } = useI18n()

const currentRow = ref<any>(null)

const getCustomeDet = async () => {
  const res = await getSnDetailApi(query.id as string)
  if (res) {
    currentRow.value = res.data
    JsBarcode('#barcode', currentRow.value.sn_id, {
      format: 'CODE128',
      lineColor: '#000',
      width: 2,
      height: 100,
      displayValue: true,
      fontSize: 16,
      margin: 10
    })
  }
}
onMounted(() => {
  getCustomeDet()
})
</script>

<template>
  <ContentDetailWrap :title="t('customer.detail')">
    <template #header>
      <BaseButton @click="go(-1)">
        {{ t('action.back') }}
      </BaseButton>
    </template>
    <div class="w-100% flex">
      <el-descriptions
        title=""
        border
        :column="1"
        label-align="left"
        content-align="left"
        class="w-full"
      >
        <el-descriptions-item :span="24" :label="t('sn.sn_number')">
          {{ currentRow?.sn_id }}
        </el-descriptions-item>
        <el-descriptions-item :span="24" :label="t('wholesalOrder.productName')">
          {{ currentRow?.product_name }}
        </el-descriptions-item>
        <el-descriptions-item :span="24" :label="t('purchase.sup')">
          {{ currentRow?.seller_name }}
        </el-descriptions-item>
        <el-descriptions-item :span="24" :label="t('inventory.conversion.warehouse')">
          {{ currentRow?.warehouse_name }}
        </el-descriptions-item>
        <el-descriptions-item :span="24" :label="t('address.status')">
          {{ currentRow?.status }}
        </el-descriptions-item>
        <el-descriptions-item :span="24" :label="t('common.creator')">
          {{ currentRow?.creator_name }}
        </el-descriptions-item>

        <el-descriptions-item :span="24" :label="t('common.create_time')">
          {{ currentRow?.create_time }}
        </el-descriptions-item>
      </el-descriptions>
      <div class="max-w-420px ml-20px flex-none">
        <svg id="barcode" class="w-full">1</svg>
      </div>
    </div>
    <div>
      <div class="pt-32px pb-24px">{{ t('sn.operation_log') }}</div>
      <el-table
        :data="currentRow?.wh_scanlog"
        highlight-current-row
        stripe
        border
        :cell-style="{ textAlign: 'center' }"
        :header-cell-style="{ textAlign: 'center' }"
      >
        <el-table-column :label="t('invoice.id')" prop="id" min-width="80" />
        <el-table-column :label="t('sn.sn_number')" prop="sn_id" min-width="200" />
        <!-- <el-table-column :label="t('wholesalOrder.productName')" prop="product_name" min-width="300">
        {{ currentRow?.product_name }}
      </el-table-column> -->
        <el-table-column
          :label="t('sn.operator')"
          prop="creator_name"
          min-width="120"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          :label="t('sn.change_operation')"
          min-width="100"
          prop="action"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          :label="t('sn.change_time')"
          prop="create_time"
          min-width="180"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          :label="t('sn.related_warehouse')"
          min-width="100"
          prop="warehouse_name"
          :show-overflow-tooltip="true"
        />
      </el-table>
    </div>
  </ContentDetailWrap>
</template>
